package com.ruoyi.examination.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.examination.dto.ExamRecordDto;
import com.ruoyi.examination.vo.ExamRecordInfoVo;
import com.ruoyi.examination.vo.ExamRecordSelectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.examination.domain.ExamRecord;
import com.ruoyi.examination.service.IExamRecordService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 考试记录Controller
 * 
 * @author hcc
 * @date 2025-10-21
 */
@RestController
@RequestMapping("/examRecord")
public class ExamRecordController extends BaseController
{
    @Autowired
    private IExamRecordService examRecordService;

    /**
     * 查询考试记录列表
     */
    @RequiresPermissions("examination:examRecord:list")
    @GetMapping("/list")
    public TableDataInfo list(ExamRecord examRecord)
    {
        startPage();
        List<ExamRecord> list = examRecordService.selectExamRecordList(examRecord);
        return getDataTable(list);
    }

    /**
     * 导出考试记录列表
     */
    @RequiresPermissions("examination:examRecord:export")
    @Log(title = "考试记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamRecord examRecord)
    {
        List<ExamRecord> list = examRecordService.selectExamRecordList(examRecord);
        ExcelUtil<ExamRecord> util = new ExcelUtil<ExamRecord>(ExamRecord.class);
        util.exportExcel(response, list, "考试记录数据");
    }

    /**
     * 获取考试记录详细信息
     */
    @RequiresPermissions("examination:examRecord:query")
    @GetMapping(value = "/{examRecordId}")
    public AjaxResult getInfo(@PathVariable("examRecordId") String examRecordId)
    {
        return success(examRecordService.selectExamRecordByExamRecordId(examRecordId));
    }

    /**
     * 新增考试记录
     */
    @RequiresPermissions("examination:examRecord:add")
    @Log(title = "考试记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamRecord examRecord)
    {
        return toAjax(examRecordService.insertExamRecord(examRecord));
    }

    /**
     * 修改考试记录
     */
    @RequiresPermissions("examination:examRecord:edit")
    @Log(title = "考试记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamRecord examRecord)
    {
        return toAjax(examRecordService.updateExamRecord(examRecord));
    }

    /**
     * 删除考试记录
     */
    @RequiresPermissions("examination:examRecord:remove")
    @Log(title = "考试记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{examRecordIds}")
    public AjaxResult remove(@PathVariable String[] examRecordIds)
    {
        return toAjax(examRecordService.deleteExamRecordByExamRecordIds(examRecordIds));
    }

    /**
     * 查询考试记录列表
     */
//    @RequiresPermissions("examination:examRecord:list")
    @GetMapping("/getExamList")
    public TableDataInfo getExamList(ExamRecordSelectVo examRecordSelectVo)
    {
        startPage();
        List<ExamRecordDto> list = examRecordService.getExamList(examRecordSelectVo);
        return getDataTable(list);
    }

    /**
     * 查询班级考试记录列表
     * lqx
     */
//    @RequiresPermissions("examination:examRecord:list")
    @GetMapping("/getExamListByClassId")
    public TableDataInfo getExamListByClassId(ExamRecordSelectVo examRecordSelectVo)
    {
        startPage();
        List<ExamRecordDto> list = examRecordService.getExamListByClassId(examRecordSelectVo);
        return getDataTable(list);
    }

    /**
     * 获取考试记录详细信息
     */
//    @RequiresPermissions("examination:examRecord:query")
    @GetMapping(value = "/getExamRecordInfo")
    public TableDataInfo getExamRecordInfo(ExamRecordInfoVo examRecordInfoVo)
    {
        startPage();
        List<ExamRecord> list = examRecordService.getExamRecordInfo(examRecordInfoVo);
        return getDataTable(list);
    }
}
